package com.flyu.myGui.myCalculator;

import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class MyListener implements ActionListener {
    CalcuPanel calcuPanel = null;
    public MyListener(CalcuPanel calcuPanel){
        this.calcuPanel = calcuPanel;
    }

    @Override
    public void actionPerformed(ActionEvent e) {
        // 获得加数
        int n1 = Integer.parseInt(calcuPanel.num1.getText());
        int n2 = Integer.parseInt(calcuPanel.num2.getText());
        // 运算
        int n3 = n1 + n2;
        // 赋值和清空
        calcuPanel.num3.setText(""+n3);
        calcuPanel.num1.setText("");
        calcuPanel.num2.setText("");
    }
}
